package class_wuziqi;

import java.util.LinkedList;
import java.util.Stack;

public class ChessArray {
	public static Chess[][] arr;
	private static ChessArray ca;
	private Stack<Chess> stack;
	public LinkedList<Chess> chessList;

	public ChessArray() {
		ca = this;
		arr = new Chess[15][15];
		stack = new Stack<Chess>();
		chessList = new LinkedList<Chess>();
	}

	public static ChessArray getInstance() {
		if (ca == null) {
			ca = new ChessArray();
		}
		return ca;
	}

	public void setChess(Chess chess) {
		int i = chess.getI();
		int j = chess.getJ();
		arr[i][j] = chess;
		stack.push(chess);
		chessList.offer(chess);
	}

	public Chess getChess(int i, int j) {
		return arr[i][j];
	}

	public void clear() {
		for (int i = 0; i < 15; i++)
			for (int j = 0; j < 15; j++)
				arr[i][j] = null;
	}

	public void remove() {
		Chess chess1 = stack.pop();
		int i = chess1.getI(), j = chess1.getJ();
		arr[i][j] = null;
		Chess chess2 = stack.pop();
		i = chess2.getI();
		j = chess2.getJ();
		arr[i][j] = null;
	}
}
